package model.dap.dao;

import model.dap.domain.Business;
import model.dap.mapper.BusinessMapper;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import common.base.DaoConfig;

public class BusinessDAO  implements BusinessMapper {

	SqlSession session  = DaoConfig.getSqlSessionFactory().openSession();
	Logger log = Logger.getLogger(BusinessDAO.class);
	// =====================================================================================================
	// REGISTER BUSINESS
	@Override
	public int insertBusiness(Business mastUser) {
		try{
			return session.getMapper(BusinessMapper.class).insertBusiness(mastUser);
		}catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		}finally{
			session.commit();
			session.close();
		}
		return 0;
	}
	
	// =====================================================================================================
	// VALIDATE BUSINESS EXIST
	@Override
	public Business validateBusinessExist(String userID) {
		// TODO Auto-generated method stub
		try {
			return session.getMapper(BusinessMapper.class).validateBusinessExist(userID);
		} catch (Exception e) {
			session.rollback();
		} finally {
			session.close();
		}
		return null;
	}
	// =====================================================================================================\
	// VALIDATE BUSINESS EMAIL EXIST
	@Override
	public Business validateBusinessEmailExist(String email) {
		// TODO Auto-generated method stub
		try {
			return session.getMapper(BusinessMapper.class).validateBusinessEmailExist(email);
		} catch (Exception e) {
			session.rollback();
		} finally {
			session.close();
		}
		return null;
	}

}
